using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Personalplaner
{
    class GGridColor
    {
        static public void SetCellColour(int r, int c, int rgb, string colourName, string shg, DataGridView grid)
        {
            Color col = Color.FromName(colourName);
            col = Color.FromArgb(rgb);

            switch (shg)
            {
                case "H": // Hintergrund
                    grid[c, r].Style.BackColor = col;
                    break;
                case "S": // Schrift
                    grid[c, r].Style.ForeColor = col;
                    break;
                default: // Hintergrund
                    grid[c, r].Style.BackColor = col;
                    break;
            }
        }

        static public void SetRowColour(int r, int rgb, string colourName, string shg, DataGridView grid)
        {
            Color col = Color.FromName(colourName);
            col = Color.FromArgb(rgb);

            switch (shg)
            {
                case "H": // Hintergrund
                    grid.Rows[r].DefaultCellStyle.BackColor = col;
                    break;
                case "S": // Schrift
                    grid.Rows[r].DefaultCellStyle.ForeColor = col;
                    break;
                default: // Hintergrund
                    grid.Rows[r].DefaultCellStyle.BackColor = col;
                    break;
            }
        }

        static public void SetColumnColour(int c, int rgb, string colourName, string shg, DataGridView grid)
        {
            Color col = Color.FromName(colourName);
            col = Color.FromArgb(rgb);

            switch (shg)
            {
                case "H": // Hintergrund
                    grid.Columns[c].DefaultCellStyle.BackColor = col;
                    break;
                case "S": // Schrift
                    grid.Columns[c].DefaultCellStyle.ForeColor = col;
                    break;
                default: // Hintergrund
                    grid.Columns[c].DefaultCellStyle.BackColor = col;
                    break;
            }
        }

        static public void SetCellColor(DataGridView grid, List<IPersonRow> row)
        {
            for (int r = 0; r < row.Count; r++)
            {
                PDienstColumn tmpColumn = null;
                int c = 0;
                while (c < row[r].Column.Count)
                {
                    if (row[r].Column[c] is PDienstColumn)
                    {
                        tmpColumn = (PDienstColumn)row[r].Column[c];
                        if (tmpColumn.Weekend == GPerson.WEEKEND.Saturday)
                        {
                            SetCellColour(r, c, PlanOption.SaColorARGB, PlanOption.SaColorName, "", grid);
                        }
                        else if (tmpColumn.Weekend == GPerson.WEEKEND.Sunday)
                        {
                            SetCellColour(r, c, PlanOption.SoColorARGB, PlanOption.SoColorName, "", grid);
                        }
                        else if (tmpColumn.Weekend == GPerson.WEEKEND.Feiertag)
                        {
                            SetCellColour(r, c, PlanOption.SoColorARGB, PlanOption.SoColorName, "", grid);
                        }

                        if (tmpColumn.RGB != 0)
                        {
                            SetCellColour(r, c, tmpColumn.RGB, tmpColumn.ColorName, "", grid);
                        }
                    }
                    c++;
                }
            }
        }
    }
}
